package android.moodle;

import android.app.Activity;
import android.app.AlertDialog;
import android.javaClasses.DataHelper;
import android.javaClasses.Game;
import android.javaClasses.XmlHandler;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TableLayout;

import java.util.ArrayList;

/**
 *This activity shows the players and the winner of a game.
 *The data shown can also be deleted from this activity.
 */
public class ScoresActivity extends Activity {
    private TableLayout table;
    private DataHelper helper;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scores);
        table = (TableLayout)findViewById(R.id.scoresTable);

        helper = new DataHelper(this);
        XmlHandler handler = new XmlHandler(this, table);

         ArrayList<Game> games = helper.selectAll();
        for(Game game : games) {
            handler.addTextToRow(game.getPlayers(), game.getWinner());

        }


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        super.onCreateOptionsMenu(menu);
        menu.add(R.id.deleteAll);
        menu.add(R.id.backToMenu);
        //MenuInflater inflater = getMenuInflater();
        //inflater.inflate(R.menu.scores_menu, menu);
   	    return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.backToMenu:
                this.finish();
            case R.id.deleteAll:
                helper.deleteAll();

        }
        return true;
    }

    //AlertDialog.Builder builder = new AlertDialog.Builder(this);
    //builder.setMessage(R.string.)



}
